// na_1.1.cpp : main project file.

#include <stdio.h>
#include <float.h>
#include <math.h>

#include "Auxiliary.h"
#include "na_1.h"

namespace na_11_ns
{

inline double itrFunction1( const double x0 )
{
    return 10.0 + x0 - 4.0 * pow( x0, 2.0 ) - pow( x0, 3.0 );
}

inline double itrFunction2( const double x0 )
{
	return sqrt( ( 10.0 - x0*x0*x0 ) / 4.0 );
}

inline double itrFunction3( const double x0 )
{
    return sqrt( 10.0 / ( x0 + 4.0 ) );
}

int na_11()
{
    printf("***************************************************\n");
    printf("Start the NA experiment 1.1, basic iteration (1)\n");

    double	inputValue = 0.00;
	char	funcNo = 0;
    itrFunctor itrFunc[3] = { NULL };

    //bind functor
    itrFunc[0] = &itrFunction1;
    itrFunc[1] = &itrFunction2;
    itrFunc[2] = &itrFunction3;

    printf("Please input which iteration equation you want to test(1~3):");
    static const char cValidInput[] = { '1', '2', '3' };
    static const unsigned int cVInputCnt = 3;
    funcNo = CheckedInputChar( cValidInput, cVInputCnt ) - '1';

    static const float cDomainUpBound[] = { +FLT_MAX, 2.1544f, +FLT_MAX };
    static const float cDomainDwBound[] = { -FLT_MAX, -FLT_MAX, -4.f };
    printf("Please give out the initial value( %1.4E ~ %1.4E ):", cDomainUpBound[funcNo], cDomainDwBound[funcNo]);
    inputValue = (double)CheckedInputFloat( cDomainDwBound[funcNo], cDomainUpBound[funcNo] );

    printf("Start iteration, with equation %d, from init value x0 = %f \n", funcNo, inputValue);

    ItrProcess( itrFunc[funcNo], inputValue );

    printf("End of iteration\n");
    printf("***************************************************\n");

    return 0;
}

}
